package com.atguigu;

import com.atguigu.mapper.UserMapper;
import com.atguigu.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;


public class test {
    @Test
    public void test_01() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis-config.xml");

        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);

        SqlSession sqlSession = sessionFactory.openSession();

        UserMapper mapper = sqlSession.getMapper(UserMapper.class);

//        User user = mapper.queryById(1);
//        System.out.println("user = " + user);

//        User user = mapper.queryByIdAndName(1, "zhangsan");
//        System.out.println("user = " + user);

//        User user = new User(1, "sjf", "88888888", "哈哈哈");
//        int i = mapper.insertUser(user);
//        System.out.println("i = " + i);

        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("name", "csy");
        int result = mapper.updateUserByMap(paramMap);
        System.out.println("result = " + result);

        sqlSession.commit();
        sqlSession.close();
    }
}
